package org.x4444.entity;

import java.io.Serializable;

import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Embeddable
public class OrderDetailPK implements Serializable {

	private static final long serialVersionUID = -460400263482161789L;

	Order order;

	Product product;

	public OrderDetailPK() {
		order=  new Order();
		product = new Product();
	}

	@Override
	public int hashCode() {
		if (order != null && product != null) {
		return 7 + 31 * order.hashCode() + 31 * product.hashCode();
		} 
		return 233;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof OrderDetailPK)) {
			return false;
		}

		OrderDetailPK o2 = (OrderDetailPK) obj;
		if (order != null && product != null) {
			return order.equals(o2.order) && product.equals(o2.product);
		}
		return false;
	}

	@ManyToOne
	@JoinColumn(name = "ORDER_ID", referencedColumnName = "ID")
	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	@ManyToOne
	@JoinColumn(name = "PRODUCT_ID", referencedColumnName = "ID")
	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}
}
